﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

using TJADRICD.CollaborativeDesignPlugin;

namespace TJADRICD.CollaborativeDesignPlugin
{
    public partial class ProjectChooseForm : System.Windows.Forms.Form
    {
        string path = "";
        bool SingleOrNot = false;
        public ProjectChooseForm(ref string path, bool single)
        {
            this.path = path;
            SingleOrNot = single;
            InitializeComponent();
        }

        private void ProjectChooseForm_Load(object sender, EventArgs e)
        {
            foreach (string webPath in Config.ProjectPath)
            {
/*                MessageBox.Show(webPath);*/
                DirectoryInfo Dir_Web = new DirectoryInfo(webPath);
                DirectoryInfo[] Dir_Pros = Dir_Web.GetDirectories();
                foreach (DirectoryInfo Dir_Pro in Dir_Pros)
                {
                    if ((Dir_Pro.Name == "Sign") || (Dir_Pro.Name == "TK"))
                    {
                        continue;
                    }
                    this.cb_ProNo.Items.Add(Dir_Pro.Name);
                }
            }
        }

        private void cb_ProNo_Selected(object sender, EventArgs e)
        {
            string fatherpath = "";
            foreach (string webPath in Config.ProjectPath)
            {
                DirectoryInfo Dir_Web = new DirectoryInfo(webPath);
                DirectoryInfo[] Dir_Pros = Dir_Web.GetDirectories();
                foreach (DirectoryInfo Dir_Pro in Dir_Pros)
                {
                    if (Dir_Pro.Name == this.cb_ProNo.Text)
                    {
                        fatherpath = webPath;
                    }
                }
            }
            this.cb_SubProNo.Items.Clear();
            DirectoryInfo Dir_Web2 = new DirectoryInfo(fatherpath + this.cb_ProNo.Text + "\\");
            DirectoryInfo[] Dir_Pros2 = Dir_Web2.GetDirectories();
            foreach (DirectoryInfo Dir_Pro in Dir_Pros2)
            {
                this.cb_SubProNo.Items.Add(Dir_Pro.Name);
            }
        }

        private void cb_SubProNo_Selected(object sender, EventArgs e)
        {
            return;
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            CommandSign.path = "";
            this.Close();
        }

        private void btn_OK_Click(object sender, EventArgs e)
        {
            if ((this.cb_ProNo.Text == "") || (this.cb_SubProNo.Text == ""))
            {
                MessageBox.Show("信息不完整！");
                return;
            }
            
            string fatherpath = "";
            foreach (string webPath in Config.ProjectPath)
            {
                DirectoryInfo Dir_Web = new DirectoryInfo(webPath);
                DirectoryInfo[] Dir_Pros = Dir_Web.GetDirectories();
                foreach (DirectoryInfo Dir_Pro in Dir_Pros)
                {
                    if (Dir_Pro.Name == this.cb_ProNo.Text)
                    {
                        fatherpath = webPath;
                    }
                }
            }

            if (SingleOrNot)
            {
                CommandSign.path = fatherpath + this.cb_ProNo.Text + "\\" + this.cb_SubProNo.Text + "\\Common\\TZ\\";
            }
            else
            {
/*                MessageBox.Show(fatherpath + this.cb_ProNo.Text + "\\" + this.cb_SubProNo.Text + "\\Common\\TZ\\");*/
                CommandSign.path = fatherpath + this.cb_ProNo.Text + "\\" + this.cb_SubProNo.Text + "\\Common\\TZ\\";
            }
            this.Close();
        }
    }
}
